home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / hdf / unix / examples.lha / examples / sds / generate.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-10-16  |  1.7 KB  |  70 lines

  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. /****************************************************************
  5. **
  6. **  generate:  generate 2-D data array for turning into image
  7. **             plus max, min, hscale, vscale, and cross-hatching
  8. **
  9. **
  10. **             The array generated, if converted to an image, 
  11. **             should display a spectrum going from top to
  12. **             bottom, with cross-hatching every 10th row and column.
  13. **             If the scale is non-uniform, the positions of the
  14. **             cross-hatches will reveal this.
  15. **
  16. ****************************************************************/
  17.     int
  18. generate(vdim, hdim, data, vscale, hscale, max, min)
  19. int   vdim, hdim;
  20. float *data, *vscale, *hscale, *max, *min;
  21. {
  22.     int i, j, width;
  23.     float *pdata, delta, newval;
  24.  
  25.     *min = 0.0;
  26.     *max = vdim;
  27.  
  28.     /* store one value per row, increasing by one for each row */
  29.     pdata = data;
  30.     for (i=0; i< vdim; i++)
  31.        for (j=0; j< hdim; j++) 
  32.            *pdata++ = (float) i+1;
  33.  
  34.     /* generate cross-hatching -- one row/col of 0's every 10th row/col */
  35.     /* rows */
  36.     pdata = data;
  37.     width = vdim/10;
  38.     if (width > 0) {
  39.     for (i=0; i<vdim; i += width) {
  40.         pdata = data + i*hdim;
  41.            for (j=0; j<hdim; j++)
  42.         *pdata++ = 0.0;
  43.     }
  44.     }
  45.     /* cols */
  46.     pdata = data;
  47.     width = hdim/10;
  48.     if (width > 0) {
  49.     for (i=0; i<vdim; i++) {
  50.         pdata = data + i*hdim;
  51.         for (j=0; j<hdim; j += width, pdata += width)
  52.         *pdata = 0.0;
  53.     }
  54.     }
  55.     
  56.  
  57.     newval = delta = 0.0;
  58.     for (i=0; i< hdim; i++, delta++) {
  59.         newval += delta;
  60.            hscale[i] = (float) (1000+newval);
  61.     }
  62.     newval = delta = 0.0;
  63.     for (i=0; i< vdim; i++, delta++) {
  64.         newval += delta;
  65.           vscale[i] = (float) (1000+newval);
  66.     }
  67.  
  68. }
  69.  
  70.